package 领扣算法.力扣计划.算法基础.所有可能的路径;

import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;

public class Main {
    LinkedList<List<Integer>> res=new LinkedList<>();
    public List<List<Integer>> allPathsSourceTarget(int[][] graph) {
        HashSet<Integer> hashSet=new HashSet<>();
        LinkedList<Integer> data=new LinkedList<>();
        data.add(0);
        plus(graph,hashSet,0,data);
        return res;
    }

    private void plus(int[][] graph, HashSet<Integer> hashSet,int index,LinkedList<Integer> data) {

        for (int i : graph[index]) {
                LinkedList<Integer> integers = new LinkedList<>(data);
                integers.add(i);
                if (i==graph.length-1){
                    res.add(integers);
                }
                else{
                    plus(graph,hashSet,i,integers);
                }

            }
        }


}
